package servlet;

import dao.EmployeeDao;
import dao.impl.EmployeeDaoImpl;
import entity.Employee;
import util.EmployeeUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/employee/update")
public class EmployeeUpdateServlet extends HttpServlet {

    //导入持久层
    private EmployeeDao employeeDao;

    public EmployeeUpdateServlet(){
        this.employeeDao = new EmployeeDaoImpl();
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Employee employee = EmployeeUtil.getEmployeeByForm(req);
        //调用方法
        try {
            employeeDao.updateEmployee(employee);
            //跳转到哪里？
            req.getRequestDispatcher("/employee").forward(req,resp);
        } catch (Exception e) {
            // e.printStackTrace();
            //跳转到哪里？
            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }
}
